/**
 * Created by ybjaa on 2017/6/9.
 */


//刷75小时的
function edit_vol(){
    var marea='#vol_info';
    var mdiv=$(marea);
    var postdata=C.form.get_form(marea);
    postdata['service_type']=[];
    $("input[name='stype_vol']:checkbox").each(function(){
        if($(this).attr("checked")){
            var user_type1=$(this).val();
            var user_type2=$(this).parent().parent().find('select').val();
            postdata['service_type'].push([user_type1,user_type2]);
        }
    });

    postdata.vol_pre_hour="75";

    try{
        $.post('info.vol.php?m=edit_vol', postdata, function(data) {
            console.log(data);
            try {
                var ret = $.evalJSON(data);
                if(ret.code=='1'){
                    mdiv.find("#"+ret.id).focus();
                    mdiv.find("#"+ret.id).parent().parent().find('.v_result').html(ret.msg);
                    mdiv.find("input[name='"+ret.id+"']").eq(0).focus();
                    mdiv.find("input[name='"+ret.id+"']").parent().parent().find('.v_result').html(ret.msg);
                    $('#'+ret.tab).click();
                }else{
                    C.alert.show(ret.msg);
                }
            } catch (e) {
                C.alert.show('error:'+data);
            }
        });
    }catch (ex){
        edit_vol();
    }


}


//刷登录的
//登录
function loginpost(username,password) {
    var pubkey='-----BEGIN PUBLIC KEY-----';
    pubkey+='MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbJ2QYNdiFlzE0mcyq7tcZc5dP';
    pubkey+='vof6696l2cJJM8kOxeXT8EonfvLzfsEGmwjNp3gvAyF14LvqT6w7oH40sFFnX358';
    pubkey+='Eb+HZXx6CZ4LOkaTW0KNS6yodsRv0uwJhFMwREqEVbqd6jcCxTGKDOieendC8x1f';
    pubkey+='sg3Muagyfawc+o+tewIDAQAB';
    pubkey+='-----END PUBLIC KEY-----';

    // 利用公钥加密
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey(pubkey);
    var upass = encrypt.encrypt(decodeURIComponent(password));
    this.login=()=> {
        try{
            $.post("http://yn.chinavolunteer.cn/app/user/login.php?m=login",{
                uname:decodeURIComponent(username),
                upass:upass,
                referer:"http%3A%2F%2Fyn.chinavolunteer.cn%2Fapp%2Fuser%2Fhome.php"

            },(data)=>console.log(data));
        }catch(ex){
            loginpost(username,password);
        }
    };



}





//登录，用户名密码
//var m1=new loginpost("输入用户名","输入密码");

//举例：用户名密码都是 test1
var m1=new loginpost("test1","test1");

//刷到服务器有http status 200的响应为止
m1.login();




//注册

class register{


    constructor(username,password,name,id,num){

        this.username=username;
        this.passowd=password;
        this.name=encodeURIComponent(name);
        this.id=id;
        this.num=num;
    }


    register(){

        try{
            $.post("http://yn.chinavolunteer.cn/app/user/register.php?m=reg_vol",
                {
                    login_name:this.username,
                    login_name_repeat:this.username,
                    login_pass:this.passowd,
                    login_pass_repeat:this.passowd,
                    login_email:"ybjaaWork%40163.com",
                    login_email_repeat:"ybjaaWork%40163.com",
                    vol_true_name:this.name,
                    vol_cert_number:this.id,
                    gender:  parseInt(this.id.substr(16,1))%2,
                    login_mobile:this.num,
                    vol_address:"%E6%B3%B0%E5%AE%89%E8%B7%AF",
                    postcode:null,
                    vol_student_flag:0,
                    college_input:null,
                    college1:null,
                    college2:null,
                    college3:null,
                    vol_student_number:null,
                    vol_public_flag:1,
                    stag_vol:"%E5%8C%BB%E7%96%97%E5%8D%AB%E7%94%9F",
                    stag_vol_val:null,
                    stype_vol:23392,
                    vol_nationality:4544,
                    vol_cert_type:4529,
                    vol_reg_year:this.id.substr(6,4),
                    vol_reg_month:this.id.substr(10,2),
                    vol_reg_day:this.id.substr(12,2),
                    vol_political:4846,
                    vol_ethnicity:4788,
                    nat_district1:null,
                    nat_district2:null,
                    nat_district3:null,
                    nat_district4:null,
                    house_district1:8474,
                    house_district2:8475,
                    house_district3:null,
                    house_district4:null,
                    vol_edu_degree:4537,
                    vol_job_title:23265,
                    graduate_year:null,
                    district1:8474,
                    district2:8475,
                    district3:null,
                    district4:null,
                    service_type:[23392]
                },(data)=> console.log(data))
        }catch (ex){
            this.register();
        }



    }

}

//a1=new register("填写用户名","填写密码","填写姓名","填写身份证",手机号（这个不加“”）);

//举例子
a1=new register("test01","password","我是姓名","530001198712121115",13912345678);

//这行代码是直到注册成功或者服务器返回某些信息填错，如果是网络问题会重复注册，直到成功
a1.register();

//可以创建数组批量注册刷，估计大家都快注册完成了，例子不写了





//批量导出信息

var userinfo=function () {
    this.username;
    this.name;
    this.zyzbh;
    this.dhhm;
}



var trs=document.getElementsByClassName("table1")[0].getElementsByTagName("tr");

let len=trs.length;

let users=new Array();

for(let i=1;i<len;i++){
    console.log(trs[i]);
    let user=new userinfo();
    user.username=trs[i].getElementsByTagName("td")[1].innerText;
    user.name=trs[i].getElementsByTagName("td")[2].children[0].innerText;
    user.zyzbh=trs[i].getElementsByTagName("td")[2].children[2].innerText;
    user.dhhm=trs[i].getElementsByTagName("td")[3].innerText.split("\n")[0];
    user.uid=trs[i].getElementsByTagName("td")[0].children[0].value;
    users.push(user);
}

let sum="";

users.forEach((u)=>{ sum+=u.username+"\t"+u.name+"\t"+u.zyzbh+"\t"+u.dhhm+"\n"  });
console(sum);






//1.获取人员UID
(function () {

    let users=[];

    getJoin2=(p)=> {
        let url="http://yn.chinavolunteer.cn/app/org/member.php";
        try{


            $.get(url+"?p="+p,
                (data)=> {
                    let table= $(data).find(".table1")[0];
                    let trs=table.getElementsByTagName("tr");
                    let len=trs.length;

                    if(len<=1) {
                        page=0;
                        console.log("完成了");
                        console.log(getUsersStr());
                        return;
                    };

                    for(let i=1;i < len;i++){
                        let user=new Object();
                        user.uid=trs[i].getElementsByTagName("td")[0].children[0].value;
                        user.zyzbh=trs[i].getElementsByTagName("td")[2].children[2].innerText;

                        user.username=trs[i].getElementsByTagName("td")[1].innerText;
                        user.name=trs[i].getElementsByTagName("td")[2].children[0].innerText;



                        user.dhhm=trs[i].getElementsByTagName("td")[3].innerText.split("\n")[0];


                        users.push(user);
                    }

                    console.log(p);
                    getJoin2(++p);


                });
        }catch (ex){
            getJoin2(p);
        }
    };

    getUsersStr=()=>{ return users.map((u)=>{ let str="";  for(let p in u){str+=u[p]+"\t";} return str;}).join("\r\n"); };


    getJoin2(1);

})();

//2.加人

 function project() {

    let uid=[
        38084284,38108800,38093609,38099512,37902327,38088755,38078393,38084424,
        38082700,37971084,37946709,37925755,37914146,37912644,37911767,37904181,
        37901130,21194893,37895092,37800094,37806104,37894048,37893215,37876635,
        37869356,37728628,37742062,37726238,37777471,37748249,37730340,37732374,
        37729158,37728289,37728568,37727223,37724991,37724302,37723483,37723157,
        37722849,37722442,37656301
    ];


    let postJoin=(url)=> {

        let newurl=url.replace(/&manage[^&]*/,"");
        let parent=this;
      //  "http://yn.chinavolunteer.cn/app/opp/opp.my.php?m=invite&item=recruit&opp_id=802236&job_id=1064889"
      //  "http://yn.chinavolunteer.cn/app/opp/opp.my.php?item=recruit&job_id=1064889&opp_id=802236&item=recruit&manage_type=0"
        try{
            $.post(newurl+"&m=invite",
                {
                    stype:"local",
                    uid:uid
                },(data)=> console.log(data))
        }catch (ex){
            postJoin();
        }
    };


    let getProjects=()=>{

        let as=document.getElementsByTagName("a");

        let zm=[];

        for(let a of as)
        {
           if(a.innerText&&  a.innerText=="招募")
           {
               zm.push(a);
           }
        }


        zm.forEach((a)=>postJoin(a.href))

    }


    this.start=()=> getProjects();



};

 p1=new project();
 p1.start();




//  操作时长

function projectTime(hour,memo) {

    let uid=[
        38084284,38108800,38093609,38099512,37902327,38088755,38078393,38084424,
        38082700,37971084,37946709,37925755,37914146,37912644,37911767,37904181,
        37901130,21194893,37895092,37800094,37806104,37894048,37893215,37876635,
        37869356,37728628,37742062,37726238,37777471,37748249,37730340,37732374,
        37729158,37728289,37728568,37727223,37724991,37724302,37723483,37723157,
        37722849,37722442,37656301
    ];


    let postJoin=(url)=> {

        let newurl=url;//url.replace(/&m=invite[^&]*|m=invite[^&]*&/,"");
        let parent=this;
        try{
            $.post(newurl+"&m=save_hour",
                {
                    hour_num:hour,
                    memo:encodeURIComponent(memo),
                    uid:uid
                },(data)=> console.log(data))
        }catch (ex){
            postJoin();
        }
    };


    let getProjects=()=>{

        let as=document.getElementsByTagName("a");

        let zm=[];

        for(let a of as)
        {
            if(a.innerText&&  a.innerText=="记时")
            {
                zm.push(a);
            }
        }


        zm.forEach((a)=>postJoin(a.href))

    }


    this.start=()=> getProjects();



};

p1=new projectTime(3,"8:00-11:00");
p1.start();


//翻页瞎搞



//批量导出信息



function getAllUsers() {

    users=[];
    flag=true;
    page=0;

    //errorIndex=8476;

    //vol_street=8476
    this.select="&vol_street=8475";

    getAllUsers.prototype.getJoin=(p)=> {
        let url="http://yn.chinavolunteer.cn/app/sys/vol.list.php";
        let newurl=url;//url.replace(/&m=invite[^&]*|m=invite[^&]*&/,"");
        let parent=this;
        try{


            $.get(newurl+"?p="+p+this.select,
                (data)=> {
                    let table= $(data).find(".table1")[0];
                    let trs=table.getElementsByTagName("tr");
                    let len=trs.length;

                    if(len<=1) {
                        page=0;
                        console.log("完成了");

                        /*if(errorIndex!=8486)
                        {
                            errorIndex++;
                            getJoin(1);
                        }*/

                        return;
                    }

                    for(let i=1; i  < len ; i++){
                        let user=new Object();
                        user.uid=trs[i].getElementsByTagName("td")[0].children[0].value;
                        user.zyzbh=trs[i].getElementsByTagName("td")[1].innerText.split("\n")[1];

                        user.username=trs[i].getElementsByTagName("td")[1].innerText.split("\n")[0];
                        user.name=trs[i].getElementsByTagName("td")[2].children[0].innerText;



                        user.dhhm=trs[i].getElementsByTagName("td")[3].innerText.split("\n")[0];

                        user.jjz=trs[i].getElementsByTagName("td")[6].innerText;
                        user.sc=trs[i].getElementsByTagName("td")[9].innerText;

                        user.error=8475;

                        users.push(user);
                    }

                    console.log(p);
                    page=p;
                    if(!flag){
                        return;
                    }
                    this.getJoin(++p);


                }).fail(()=>{
                    console.log("fail");
                    this.getJoin(p);
            });
        }catch (ex){
            this.getJoin(p);
        }
    };


    getAllUsers.prototype.getJoin2=(p)=> {
        let url="http://yn.chinavolunteer.cn/app/sys/vol.list.php";
        let newurl=url;//url.replace(/&m=invite[^&]*|m=invite[^&]*&/,"");
        let parent=this;
        try{


            $.get(newurl+"?p="+p,//+this.select,
                (data)=> {
                    let table= $(data).find(".table1")[0];
                    let trs=table.getElementsByTagName("tr");
                    let len=trs.length;

                    if(len<=1) return;

                    for(let i=1;i<len;i++){
                        let user=new Object();
                        user.uid=trs[i].getElementsByTagName("td")[0].children[0].value;
                        user.zyzbh=trs[i].getElementsByTagName("td")[2].children[2].innerText;

                        user.username=trs[i].getElementsByTagName("td")[1].innerText;
                        user.name=trs[i].getElementsByTagName("td")[2].children[0].innerText;



                        user.dhhm=trs[i].getElementsByTagName("td")[3].innerText.split("\n")[0];


                        users.push(user);
                    }

                    console.log(p);
                    page=p;
                    if(!flag){
                        return;
                    }
                    this.getJoin2(++p);


                });
        }catch (ex){
            this.getJoin2(p);
        }
    };


    let getProjects=(p=1)=>{

        this.getJoin(p);

    };

    getAllUsers.prototype.getUsersStr=()=>{ return users.map((u)=>{ let str="";  for(let p in u){str+=u[p]+"\t";} return str;}).join("\r\n"); };

    getAllUsers.prototype.getUsers=()=>users;


    getAllUsers.prototype.start=()=> getProjects();

    getAllUsers.prototype.resume=()=>{flag=true; getProjects(page);};

    getAllUsers.prototype.stop=()=>{flag=false; };




};

p1=new getAllUsers();
p1.start();

us2=p1.getUsers().map((u)=>{ let str=""; for(let p in u){str+=u[p]+"\t";} return str;});
console.log(p1.getUsers().map((u)=>{ let str=""; for(let p in u){str+=u[p]+"\t";} return str;}).join("\r\n"));



//*************************法宣老版本*****************************
//每天刷100分

/*

(function () {

    //设置时间
    /!* var d1=new Date();
     var m1=d1.getMinutes();
     var date=new Array(d1,)
     var d2=d1.setMinutes((m1+1)%60);
     var d3=d1.setMinutes((m1+2)%60);*!/


    var s1=document.cookie.split(";");
    var r=/^loginUser=/;
    var r1=/userAccount":"([0-9]*)"/;
    var r2=/domainCode":"([0-9]*)"/;

    if(!s1||s1.length<=0)
    {
        return;
    }

    var s2= decodeURIComponent(s1.filter((s)=>r.test(s.trim())));

    var userAccount=r1.exec(s2)?r1.exec(s2)[1]:"";
    var domainCode=r2.exec(s2)?r2.exec(s2)[1]:"";
    console.log(userAccount);
    console.log(domainCode);

    function f1() {
        try{
            $.post("http://xf.faxuan.net/pss/service/postPoint?operateType=epoint&userAccount="+userAccount+
                "&domainCode="+domainCode+"&timestamp=" +new Date()+ "&exerScore=6&expointValue=0").
            fail(()=>{
                f1();
            });
        }catch (ex){
            f1();
        }
    }

    function f2() {
        try{
            $.get("http://xf.faxuan.net/pss/service/postPoint?operateType=spoint&userAccount="+userAccount+
                "&domainCode="+domainCode+"&timestamp="+ new Date() +"&stime=88").
            fail(()=>{
                f2();
            });
        }catch (ex){
            f2();
        }
    }

    function f3() {
        try{
            $.get("http://xf.faxuan.net/pss/service/postPoint?operateType=lpoint&userAccount="+userAccount+
                "&domainCode="+domainCode+"&timestamp="+ new Date() +"&stime=88").
            fail(()=>{
                f3();
            });
        }catch (ex){
            f3();
        }
    }

    function f4() {
        try{
            $.get("http://xf.faxuan.net/pss/service/postPoint?operateType=ipoint&userAccount="+userAccount+
                "&domainCode="+domainCode+"&timestamp="+ new Date()).
            fail(()=>{
                f4();
            });
        }catch (ex){
            f4();
        }
    }



    f1();
    f2();
    f3();

    f1();
    f2();
    f3();
    f4();

    f1();
    f2();

})();*/



//*********************************法宣**************************
(function () {

    var count = 0;




    function countAdd(str) {


        if (str==="end"){
            console.log("刷完了");
        } else
        {
            count++;
            console.log(str + ":" + count);
        }
    }

    var integral = function () {

        integral.prototype.time=1100;

        this.funcArray=null;


        var r1 = /userAccount":"([0-9]*)"/;
        var r2 = /domainCode":"([0-9]*)"/;

        var s2 = decodeURIComponent(document.cookie ? document.cookie : "");

        this.userAccount = r1.exec(s2) ? r1.exec(s2)[1] : "";
        this.domainCode = r2.exec(s2) ? r2.exec(s2)[1] : "";


        integral.prototype.delegate=function (str) {
            countAdd(str);
            this.start();
        }
        


        //刷答题分的
        integral.prototype.f1= function() {
            var parent = this;

            try {
                $.post("http://xf.faxuan.net/pss/service/postPoint?operateType=epoint" +
                    "&userAccount=" + this.userAccount +
                    "&domainCode=" + this.domainCode +
                    "&"+"timestamp=" + new Date() +
                    "&exerScore=2" +
                    "&expointValue=20", () => {parent.delegate("刷分的");})
                    .fail(() => {
                        parent.f1();
                });
            } catch (ex) {
                parent.f1();
            }
        }

        //刷10分钟的
        integral.prototype.f2=function() {
            var parent = this;

            try {
                $.get("http://xf.faxuan.net/pss/service/postPoint?operateType=spoint" +
                    "&userAccount=" + this.userAccount +
                    "&domainCode=" + this.domainCode +
                    "&"+"timestamp=" + new Date() +
                    "&stime=88",
                    () => parent.delegate("刷10分钟的"))
                    .fail(() => {
                        parent.f2();
                });
            } catch (ex) {
                parent.f2();
            }
        }

        //刷登录的
        integral.prototype.f3=function() {
            var parent = this;

            try {
                $.get("http://xf.faxuan.net/pss/service/postPoint?operateType=lPoint" +
                    "&userAccount=" + this.userAccount +
                    "&domainCode=" + this.domainCode +
                    "&"+"timestamp=" + new Date(),
                    () => parent.delegate("刷登录的"))
                    .fail(() => {
                        parent.f3();
                });
            } catch (ex) {
                parent.f3();
            }
        }

        //刷1分的
        integral.prototype.f4=function() {
            var parent = this;
            try {
                $.get("http://xf.faxuan.net/pss/service/postPoint?operateType=iPoint" +
                    "&userAccount=" + this.userAccount +
                    "&domainCode=" + this.domainCode +
                    "&"+"timestamp=" + new Date(),
                    () => parent.delegate("刷1分的"))
                    .fail(() => {
                        parent.f4();
                });
            } catch (ex) {
                parent.f4();
            }
        }

        integral.prototype.start=function () {
            if(this.funcArray===null) {
                this.funcArray=[];
                Array.prototype.push.call(this.funcArray,this.f1,this.f2,this.f3,this.f4);
            }
            if(this.funcArray.length>0) {
                setTimeout(()=>this.funcArray.shift().apply(this),this.time);
            }
            else {
                start();
            }






        }


    }


    var total=3;

    function start() {
        if(total>0) {
            total--;
            new integral().start();
        }else {
            console.log("刷完了")
        }
    }
    start();

    /*//刷三次
    new integral().start();
    setTimeout(()=>new integral().start(),1100);
    setTimeout(()=>new integral().start(),2200);*/


})();



